package org.rsbot.script.wrappers;

import org.rsbot.bot.Bot;

public class RSNPC extends RSCharacter {
	
	private final org.rsbot.client.RSNPC npc;
	

	/**
	 * @version 1.1 - 04/25/2011
	 * Cleaned it up. - Henry
	 */
	public RSNPC(final org.rsbot.client.RSNPC npc, final Bot bot) {
		super(bot);
		
		this.npc = npc;
	}
	
	@Override
    public org.rsbot.client.RSNPC getAccessor() {
	    return npc;
	}

	/**
	 * Used to get actions available to be done on <b>RSNPC</b>.
	 * 
	 * @return <b>String</b> array that contains actions available for this <b>RSNPC</b>.
	 */
	public String[] getActions() {
		final org.rsbot.client.RSNPCDef def = getDefInternal();
		if (def != null)
			return def.getActions();
		return new String[0];
	}

        /**
	 * Performs an action on the npc instance (tall and skinny)
	 * without any randomly generated mousepaths.
	 * 
	 * @param option
	 *            The option to be clicked (If available).
	 * @return <tt>true</tt> if the option was found; otherwise <tt>false</tt>.
	 * @see #do(RSNPC, String, boolean)
	 */
	@Override
    public boolean action(final String option) {
		return this.action(option, false);
	}

        /**
	 * Performs an action on a npc (tall and skinny).
	 *
	 * @param action The action of the menu entry to be clicked (if available).
	 * @param option The option of the menu entry to be clicked (if available).
	 * @return <tt>true</tt> if the option was found; otherwise <tt>false</tt>.
	 */
	@Override
    public boolean action(final String action, final String option) {
		final RSModel model = getModel();
		return model != null && isValid() && getModel().action(action, option);
	}

	/**
	 * Used to get <b>RSNPC</b> ID.
	 * 
	 * @return <b>Integer</b> that contains the ID of <b>RSNPC</b>.
	 */
	public int getID() {
		final org.rsbot.client.RSNPCDef def = getDefInternal();
		if (def != null)
			return def.getType();
		return -1;
	}

	/**
	 * Used to get <b>RSNPC</b> name.
	 * 
	 * @return <b>String</b> that contains the name of <b>RSNPC</b>.
	 */
	@Override
	public String getName() {
		final org.rsbot.client.RSNPCDef def = getDefInternal();
		if (def != null)
			return def.getName();
		return "";
	}

	/**
	 * Used to get <b>RSNPC</b> combat level.
	 * 
	 * @return <b>Integer</b> that contains the current level of <b>RSNPC</b>.
	 */
	@Override
	public int getLevel() {
		final org.rsbot.client.RSNPCDef def = getDefInternal();
		if (def != null)
			return def.getLevel();
		return -1;
	}

	/**
	 * Used to get <b>RSNPC</b> information in a <b>String</b>
	 * 
	 * @return <b>String</b> that contains name and actions of <b>RSNPC</b>.
	 */
	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();
		for (final String act : getActions()) {
			sb.append(act);
			sb.append(",");
		}
		if (sb.length() > 0) {
			sb.setLength(sb.length() - 1);
		}
		return "NPC[" + getName() + "], ID=["+ getID() +"], actions=[" + sb.toString() + "]"
				+ super.toString();
	}
	
	org.rsbot.client.RSNPCDef getDefInternal() {
		if (npc == null)
			return null;
		else
			return npc.getRSNPCDef();
	}
}
